const db = wx.cloud.database()
Page({
  // 登陆功能
  create_login(e) {
    let user = e.detail.value
    console.log('user', user)
    if (!user.phone) {
      wx.showToast({
        icon: 'none',
        title: '请填写手机',
      })
    } else if (!user.password) {
      wx.showToast({
        icon: 'none',
        title: '请填写密码',
      })
    } else {
      db.collection('user').where({
          phone: user.phone,
          password: user.password
        }).get()
        .then(res => {
          console.log('获取登录结果', res)
          let users = res.data
          if (users && users.length > 0) {
            wx.showToast({
              title: '登陆成功',
            })
            wx.navigateTo({
              url: '/pages/admin/admin',
            })
          } else {
            wx.showToast({
              title: '账号密码错误',
              icon: "error"
            })
          }
        })
        .catch(res => {
          console.log('获取登录结果失败', res)
        })
    }
  },

})